<!DOCTYPE html>
<html>

<head>
  <script src="../node_modules/angular/angular.js"></script>
</head>

<body ng-app="demo">
  <div ng-controller="DemoController">
    <button ng-click="queryResult()">获取</button>
    <button ng-click="saveResult()">保存</button>
    <p>结果：{{ result }}</p>
  </div>
  <script>
    const demo = angular.module('demo', [])
    demo.controller('DemoController', function ($scope, $http) {
      $scope.result = '...'

      $scope.queryResult = () => {
        $http({
          method: 'GET',
          url: './result.txt',
          headers: {},
          eventHandlers: {
            readystatechange(e) {
              console.log(e)
              // e.target.readyState
            }
          },
          data: { test: 'test' },
          params: { name: 'zgl' },
        }).then(res => {
          console.log(res.data)
          $scope.result = res.data
        })
      }

      $scope.saveResult = () => {
        $http({
          method: 'POST',
          url: './some-url',
          headers: {},
          data: { result: $scope.result }
        }).then(res => {
          console.log(res.data)
        }).catch(err => {
          console.log(err)
        })
      }
    });
  </script>
</body>

</html>